package cn.wolfcode.web.controller;


import cn.wolfcode.domain.ExamEmployee;
import cn.wolfcode.service.IExamEmployeeService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/examEmployee")
public class ExamEmployeeController {

    @Autowired
    private IExamEmployeeService examEmployeeService;


    @RequiredPermission(name="答题页面",expression="examEmployee:record")
    @RequestMapping("/record")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<ExamEmployee> pageInfo = examEmployeeService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "exam/record";
    }


    @RequiredPermission(name="答题删除",expression="examEmployee:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           examEmployeeService.delete(id);
        }
        return "redirect:/examEmployee/record";
    }


    @RequiredPermission(name="答题新增/编辑",expression="examEmployee:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(ExamEmployee examEmployee) {
        if (examEmployee.getId() == null) {
            examEmployeeService.save(examEmployee);
        } else {
            examEmployeeService.update(examEmployee);
        }
        return "redirect:/examEmployee/list";
    }


    @RequiredPermission(name="答题新增/编辑跳转",expression="examEmployee:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("examEmployee",examEmployeeService.get(id));
        }
        return "examEmployee/input";
    }
}
